<div id="app"></div>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://cdn.bootcss.com/babel-standalone/6.26.0/babel.min.js"></script>
<script type="text/babel">
  // 定义组件
  class App extends React.Component {
    state = {
      num: 0,
    };
    render() {
      return (
        <fieldset>
          <legend>setState合并</legend>
          <h1>num {this.state.num}</h1>
        </fieldset>
      );
    }

    componentDidMount() {
      // react控制：异步合并
      //   this.setState({ num: this.state.num + 1 });
      //   this.setState({ num: this.state.num + 1 });
      // 非react控制：同步不合并
      //   document.body.onclick = () => {
      //     this.setState({ num: this.state.num + 1 });
      //     this.setState({ num: this.state.num + 1 });
      //   };
      // 非react控制：同步不合并
      setTimeout(() => {
        this.setState({ num: this.state.num + 1 });
        this.setState({ num: this.state.num + 1 });
      });
    }
  }
  // 渲染
  ReactDOM.render(<App />, document.querySelector("#app"));
</script>
